package com.qboot.core.config;

import com.qboot.common.consts.CommonConst;
import com.qboot.core.interceptor.PreviewInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC 配置
 *
 * @author Tellsea
 * @date 2022/12/27
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(CommonConst.FILE_PREFIX + "/**")
                .addResourceLocations("file:" + CommonConst.UPLOAD_PATH + "/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new PreviewInterceptor()).addPathPatterns("/**");
    }
}
